package chen.nf.util.result;

import chen.nf.util.RowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author czl
 * @Date 2024-05-10
 */
public class ColumnListHandler<T> extends AbstractListHandler<T>{
    private int columnIndex;
    private String columnName;

    public ColumnListHandler(int columnIndex) {
        this.columnIndex = columnIndex;
    }

    public ColumnListHandler(String columnName) {
        this.columnName = columnName;
    }

    @SuppressWarnings("unchecked")
    @Override
    public T handleRow(ResultSet rs) throws SQLException {
        if(this.columnName == null) {
            return (T) RowProcessor.toValue(rs, this.columnIndex);
        }
        return (T) RowProcessor.toValue(rs, this.columnName);
    }
}
